﻿@using StudentPortal.Lib;
<!-- BEGIN HEADER -->
<div class="header navbar navbar-inverse navbar-fixed-top" id="header">
    <!-- BEGIN TOP NAVIGATION BAR -->
    <div class="navbar-inner">
        <div class="container-fluid">
            <!-- BEGIN LOGO -->
            <a href="#" class="brand"><span style="color:#fff">CỔNG THÔNG TIN </span><span style="color:red">SINH VIÊN</span></a>
            <!-- END LOGO -->
            <!-- BEGIN RESPONSIVE MENU TOGGLER -->
            <a href="javascript:;" class="btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse">
                <img src="~/Content/themes/assets/img/menu-toggler.png" alt="" />
            </a>
            <!-- END RESPONSIVE MENU TOGGLER -->
            <!-- BEGIN TOP NAVIGATION MENU -->
            <ul class="nav pull-right">
                @if (ViewBag.IsUserLoggedIn)
                {
                    <script type="text/javascript">
                        $(document).ready(function () {
                            $('#header_inbox_bar').data('FeedsCount', 0);
                            $('#header_notification_bar').data('NotificationsCount', 0);
                            function GetNewFeed() {
                                $.ajax({
                                    url: '@Url.Action("getNewFeeds", "Home", new { Area=""})',
                                    dataType: 'json',
                                    success: function (o) {
                                        if (o.FeedsCount != $('#header_inbox_bar').data('FeedsCount')) {
                                            $('#header_inbox_bar').data('FeedsCount', o.FeedsCount);
                                            if (o.FeedsCount == 0)
                                                $('#header_inbox_bar>a').html('');
                                            else
                                                $('#header_inbox_bar>a').html('<i class="icon-envelope-alt"></i><span class="badge">' + o.FeedsCount + '</span>');
                                            var feedHtml = '<li>' +
                                                                '<p>Bạn có ' + o.FeedsCount + ' thông báo mới</p>' +
                                                            '</li>';;
                                            for (var i in o.Feeds) {
                                                var feed = o.Feeds[i];
                                                postdate = new Date(parseInt(feed.Postdate.substr(6)));
                                                feedHtml+='<li>'+
                                                                '<a href="'+feed.Link+'">'+
                                                                    '<span class="subject">'+
                                                                        '<span class="from">'+feed.From+'</span>'+
                                                                        '<span class="time">' + postdate.toString('dd/MM/yyyy') + '</span>' +
                                                                    '</span>'+
                                                                    '<span class="message">' + feed.Title +
                                                                    '</span>'+
                                                                '</a>'+
                                                            '</li>';
                                            }
                                            feedHtml += '<li class="external">' +
                                                            '<a href="@Url.Action("Inbox", "Message", new { Area = ""})">Xem tất cả thông báo <i class="m-icon-swapright"></i></a>' +
                                                        '</li>';
                                            $('#header_inbox_bar>ul').html(feedHtml);
                                        }
                                        if (o.NotificationsCount != $('#header_notification_bar').data('NotificationsCount')) {
                                            $('#header_notification_bar').data('NotificationsCount', o.NotificationsCount);
                                            if (o.NotificationsCount == 0)
                                                $('#header_notification_bar>a').html('');
                                            else
                                                $('#header_notification_bar>a').html('<i class="icon-warning-sign"></i><span class="badge">' + o.NotificationsCount + '</span>');
                                            var notificationsHtml = '<li>'+
                                                                        '<p>Bạn có '+ o.NotificationsCount+ ' thông báo mới</p>'+
                                                                    '</li>';
                                            for (var i in o.Notifications) {
                                                var notification = o.Notifications[i];
                                                postdate = new Date(parseInt(notification.Postdate.substr(6)));
                                                notificationsHtml +='<li>' +
                                                                    '<a href="' + notification.Link + '">' +
                                                                        '<span class="label label-important"><i class="icon-bolt"></i></span>' +
                                                                        notification.Title +
                                                                        '<span class="time pull-right">' + postdate.toString('dd/MM/yyyy') + '</span>' +
                                                                    '</a>' +
                                                                '</li>';
                                            }
                                            notificationsHtml += '<li class="external">' +
                                                                    '<a href="@Url.Action("Inbox", "Message", new { Area = ""})">Xem tất cả thông báo <i class="m-icon-swapright"></i></a>' +
                                                                '</li>';
                                            $('#header_notification_bar>ul').html(notificationsHtml);
                                        }
                                        //setTimeout(GetNewFeed, 1000);
                                    }
                                });
                            }
                            GetNewFeed();
                        });
                    </script>
                <!-- BEGIN NOTIFICATION DROPDOWN -->
                <li class="dropdown" id="header_notification_bar">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <i class="icon-warning-sign"></i>
                    </a>
                    
                    <ul class="dropdown-menu extended notification">
                        <li>
                            <p>Bạn có 0 thông báo mới</p>
                        </li>
                        <li class="external">
                            <a href="@Url.Action("Inbox", "Message", new { Area = ""})">Xem tất cả thông báo <i class="m-icon-swapright"></i></a>
                        </li>
                    </ul>
                </li>
                <!-- END NOTIFICATION DROPDOWN -->
                <!-- BEGIN INBOX DROPDOWN -->
                <li class="dropdown" id="header_inbox_bar">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <i class="icon-envelope-alt"></i>
                    </a>
                    <ul class="dropdown-menu extended inbox">
                        <li>
                            <p>Bạn có 0 tin nhắn mới</p>
                        </li>
                        <li class="external">
                            <a href="@Url.Action("Inbox", "Message", new { Area = ""})">Xem tất cả tin nhắn mới <i class="m-icon-swapright"></i></a>
                        </li>
                    </ul>
                </li>
                <!-- END INBOX DROPDOWN -->
                
                

                    <!-- BEGIN USER LOGIN DROPDOWN -->

                    <li class="dropdown user">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <img alt="" src="~/Images/trung.jpg" style="max-height:29px;max-width:29px;"/>
                            <span class="username">@ViewBag.FullName</span>
                            <i class="icon-angle-down"></i>
                        </a>
                        <ul class="dropdown-menu">
                            @if (ViewBag.IsUserLoggedIn)
                            {
                                <li><a href="@Url.Action("Index", "HoSo", new { Area=""})"><i class="icon-user"></i>&nbsp;Hồ sơ</a></li>
                                <li><a href="@Url.Action("Manage","Account", new { Area=""})"><i class="icon-lock"></i>&nbsp;Đổi mật khẩu</a></li>
                            }
                            @if(ViewBag.IsSinhVien){
                            <li><a href="@Url.Action("Index", "ThoiKhoaBieu", new { Area=""})"><i class="icon-calendar"></i>&nbsp;Thời khóa biểu</a></li>
                            <li><a href="@Url.Action("Diem","TraCuu", new { Area=""})"><i class="icon-tasks"></i>&nbsp;Điểm học tập</a></li>
                            }
                            
                            <li class="divider"></li>
                            <li>
                                @using (Html.BeginForm("LogOff", "Account", new { Area = "" }, FormMethod.Post, new { id = "logoutForm", style = "display:none;" }))
                                {
                                    @Html.AntiForgeryToken()	
                                }
                                <a href="javascript:$('#logoutForm').submit()"><i class="icon-key"></i>Đăng xuất</a>
                            </li>
                        </ul>
                    </li>

                    <!-- END USER LOGIN DROPDOWN -->
                }else{
                    <li class="user">
                        <a href="@Url.Action("Login", "Account", new { Area = "" })">Đăng nhập</a>
                    </li>
                }
            </ul>
            <!-- END TOP NAVIGATION MENU -->
        </div>
    </div>
    <!-- END TOP NAVIGATION BAR -->
</div>
<!-- END HEADER -->
